class Right < ActiveRecord::Base
  has_and_belongs_to_many :roles
  validates_uniqueness_of :name

  def role_authorized?(role)
    return false unless role
    roles.contains?(role)
  end

  def user_authorized?(user)
    return false unless user
    roles.detect{|role| role_authorized?(role)}
  end

end
